package servidor;

import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;

public class SocketServer implements Runnable {
	private Integer porta;
	
	public SocketServer(Integer porta){
		this.porta = porta;
	}
	
	@Override
	public void run() {
		try {
			SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
			SSLServerSocket servidor = (SSLServerSocket) factory.createServerSocket(porta);
			
			while (true) {
				SSLSocket socket = (SSLSocket) servidor.accept();
				
				ConexaoCliente conexaoCliente = new ConexaoCliente(socket);
				Thread threadCliente = new Thread (conexaoCliente);
				threadCliente.start();
			}
			
		} catch (Exception e) {
			Servidor.getInterfaceGrafica().adicionaDados("SocketServer Error: " + e.toString());
		}
	}
}